<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/my_sty.css">
    <style>
        body {
            /* url() 为自定义鼠标样式路径 */
            cursor: url(image/pointer.png), auto;
        }

        .alert {
            margin: auto;
            margin-top: 1rem;
            width: 500px;
            background-color: rgba(191, 240, 213, 0.445);
        }
    </style>
</head>

<body style="cursor: url(image/pointer.png), auto;">
   
    <!-- 标题 -->
    <div class="text-center" style="margin-top: 12rem;">
        <div id="title" style="font-family: '楷体';">
            <h1>欢迎登陆微说说</h1>
        </div>
    </div>
    <!-- 主体 -->
    <div class="container">
        <div class="box shadow p-3 mb-5">
            <div class="row">
            </div>
    
            <form id="loginForm" action="/loginDone" method="POST">
                <!-- 文本框 -->
                <div id="body_middle">
                    <!-- 账号框 -->
                    <div class="row">
                        <div class="col">
                            <center>
                                <input type="text" class="form-control " id="username" name="username"
                                    placeholder="用户名/手机号/邮箱" style="width: 50%; text-align: center;">
                            </center>
                        </div>
                    </div>
                    <!-- 密码框 -->
                    <div class="row">
                        <div class="col">
                            <center>
                                <input type="password" class="form-control" id="password" name="password"
                                    placeholder="请输入密码" style="width: 50%; text-align: center">
                                <!-- 功能小眼睛 -->
                                <img src="image/close_眼睛.png" alt="" id="eyes"
                                    style="margin-right: 6.6rem; margin-top: 0px; ">
                            </center>
                        </div>
                    </div>
                </div>
    
                <!-- 辅助板块 -->
                <div>
                    <div class="row">
                        <div class="col">
    
                        </div>
                    </div>
                    <!-- 按钮组件 -->
                    <!-- <div>
                        <a href="#" onclick="register()">
                            注册账号
                        </a>
                    </div> -->
                </div>
            </div>
            <div style="text-align: center; margin-top: 14rem;">
                <button type="button" class="btn btn-outline-success" style="width: 14.5rem; border-radius: 5rem;  box-shadow: 1px 1px 4px rgb(65, 57, 54);" onclick="jump()">登录</button><br>
                <button type="button" class="btn btn-outline-success" style="width: 14.5rem; border-radius: 5rem;   box-shadow: 1px 1px 4px rgb(65, 57, 54); margin-top: 1rem;" onclick="register()">注册账号</button>
            </div>
             <!-- 提示 -->
            <div class="alert alert-success text-center invisible" role="alert">
                <strong>提示: </strong>
                <font id="msgId">此处为至尊林宝</font>
            </div>
        </div>
    </form>
    <script src="https://cdn.bootcss.com/axios/0.18.0/axios.min.js"></script>
    <script src="js/jquery-3.5.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- 登录页输入框焦点逻辑 -->
    <script src="js/login_input_focus.js"></script>
    <!-- 小眼睛——显示隐藏密码实现逻辑 -->
    <script src="js/icon_click.js"></script>
    <!-- 网页特效 -->
    <script src="js/a.js"></script>
    <script src="js/b.js"></script>

    <!-- JQuery跳转代码 -->
    <script>
         function register(){
            window.location.href='/register';
        }
        function jump() {
            // 获取表单数据
            let uid = $('#username').val();
            let pwd = $('#password').val();

            // 判断用户名、密码是否为空，为空则提示；不为空则向服务器提交
            if (uid.length > 0 && pwd.length > 0) {
                axios({
                    method: 'post',
                    url: '/loginDone',
                    data: $('#loginForm').serialize(),
                }).then(function (res) {
                    // axios工具下，服务器真正返回的数据在返回对象的data中
                    res = res.data;
                    
                    if (res.code === 200) {
                        window.location.href = '/';
                    } else {
                        alert_fn(res.msg);
                        console.log(res.msg);
                    }
                }).catch((err) => {
                    alert_fn(err);
                    console.log(err);
                });
            } else {
                alert_fn('用户名、密码不能为空');
            }
        }

        // 包装了显示（以及自动隐藏）消息警告的动作
        function alert_fn(msg){
            $('#msgId').text(msg);
            $('.alert').removeClass('invisible');
            setTimeout(() => {
                $('.alert').addClass('invisible');
            }, 3000);
        }
    </script>
</body>

</html>